#!/usr/bin/sh

modprobe micom
echo "init frontpanel"
modprobe simu_button

if [ -e /var/etc/.firstboot ]; then
   #fp_control does not work here
   echo "WAIT 1 min" >/dev/vfd
   echo "WAIT 1 min"
   rm /var/etc/.firstboot
   touch /dev/.devfsd
fi

echo "Booting" > /dev/vfd

if [ -e /etc/init.d/mountvirtfs ]; then
   /etc/init.d/mountvirtfs start
fi

if [ -e /etc/init.d/portmap ]; then
   /etc/init.d/portmap start
fi

modprobe e2_proc

if [ -e /etc/init.d/autofs ]; then
   /etc/init.d/autofs start
fi

if [ ! -e /var/etc/.firstboot ]; then

   echo "Starting DEBUG Interface"
if [ -e /etc/init.d/mountall ]; then
   /etc/init.d/mountall start
fi

   echo "init stmfb"
   modprobe stmcore-display-sti7111
   if  grep -q "config.av.videoport=HDMI" /etc/enigma2/settings; then
         modprobe stmfb display0=1280x720-32@50:12m:pal:yuv:yuv;
        echo "VIDEO:scart"
        VIDEO=scart
   else
        modprobe stmfb display0=720x576-32@50i:12m:pal:yuv:rgb;
        echo "VIDEO:hdmi_component"
        VIDEO=hdmi_component
    fi

   echo "LOADING MODULES"

   echo "load audio firmware"
   /usr/bin/ustslave /dev/st231-1 /boot/audio.elf
   echo "load video firmware"
   /usr/bin/ustslave /dev/st231-0 /boot/video.elf

   echo "init embx"
   modprobe embxshell
   modprobe embxmailbox mailbox0=0xfe211000:136:set2 mailbox1=0xfe212000:0 ;
   modprobe embxshm mailbox0=shm:0:7:0x60000000:0:256:256:0:512:0x40000000:0x10000000 ;
   modprobe mme_host transport0=shm

   echo "init AVS"
   modprobe avs type=stv6419

   echo "init player 191"
   modprobe mmelog
   modprobe ksound
   modprobe p2div64
   modprobe stm_v4l2
   modprobe stmvout
   modprobe stmvbi
   modprobe pseudocard

   modprobe stv090x
   modprobe starci
   modprobe pti
   modprobe stm_monitor
   modprobe stmsysfs
   modprobe stmdvb
   modprobe player2 discardlateframe=0
   modprobe sth264pp
   modprobe stmalloc
   modprobe platform
   modprobe silencegen

   modprobe bpamem
   mknod /dev/bpamem c 153 0


    showiframe -p /usr/share/bootlogo.mvi &
   stfbcontrol a 0

   modprobe smartcard
   mknod /dev/sci0 c 169 0

   /usr/bin/evremote2 &

if [ -e /etc/init.d/mountall ]; then
   /etc/init.d/mountall start
fi

if [ -e /etc/init.d/vsftpd ]; then
   /etc/init.d/vsftpd start
fi
   /usr/sbin/inetd

   /etc/init.d/network start &

   echo "LOADING e2"
   echo "LOADING e2" > /dev/vfd

   stfbcontrol a 255

  # /etc/init.d/fixdate.sh

   until false
   do
      echo "starting e2->"
      /usr/bin/enigma2
      rtv=$?
      echo "e2 ended <- RTV: " $rtv
      case "$rtv" in
		0) echo "0"
		   echo "E2 ERROR"
      	   init 6;;
		1) echo "1"
		   echo "SHUTDOWN"
		   init 0;;
		2) echo "2"
		   echo "REBOOT"
		   init 6;;
		3) echo "3"
		   echo "E2 RESTART"
		   echo "0" > /proc/progress
		   showiframe -p /usr/share/bootlogo.mvi &;;
		*) echo "*"
		   echo "ERROR"
           init 6;;
      esac
   done 
fi
